"use strict";
const moment = require("moment");

module.exports = app => {
  const { STRING, INTEGER, DATE, TEXT } = app.Sequelize;

  const Model = app.model.define(
    "Blog",
    {
      blogId: {
        type: INTEGER,
        primaryKey: true,
        autoIncrement: true,
      },
      title: STRING,
      content: TEXT,
      desc: STRING,
      banner: STRING,
      categoryId: INTEGER,
      createdAt: {
        type: DATE,
        get() {
          return moment(this.getDataValue("createdAt")).format(
            "YYYY-MM-DD HH:mm:ss"
          );
        },
      },
      updatedAt: {
        type: DATE,
        get() {
          return moment(this.getDataValue("updatedAt")).format(
            "YYYY-MM-DD HH:mm:ss"
          );
        },
      },
      deletedAt: DATE,
    },
    {
      tableName: "blog",
      timestamps: true, // 自动填充创建和更新时间
      paranoid: true, // 逻辑删除
    }
  );

  return Model;
};
